#include "navigation.h"
#include "ui_navigation.h"

Navigation::Navigation(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Navigation)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    navinames_tcms_cn_<<"运行"<<"车辆"<<"空调"<<"广播"<<"设置"<<"事件"<<"检修";
    navinames_cctv_cn_<<"实时监控"<<"录像回放"<<"媒体管理";
    InitTCMSNaviBtns();
    InitCCTVNaviBtns();
}

Navigation::~Navigation()
{
    delete ui;
}

void Navigation::InitTCMSNaviBtns()
{
    if(navinames_tcms_cn_.isEmpty())
        return;
    uint8_t btn_cnt = navinames_tcms_cn_.length();

    navi_btns_tcms_.append(ui->btn_tcms_1);
    navi_btns_tcms_.append(ui->btn_tcms_2);
    navi_btns_tcms_.append(ui->btn_tcms_3);
    navi_btns_tcms_.append(ui->btn_tcms_4);
    navi_btns_tcms_.append(ui->btn_tcms_5);
    navi_btns_tcms_.append(ui->btn_tcms_6);
    navi_btns_tcms_.append(ui->btn_tcms_7);

    for(int i=0;i<btn_cnt;i++)
    {
        navi_btns_tcms_[i]->setText(navinames_tcms_cn_.at(i));
        navi_btns_tcms_[i]->setCheckable(true);
        navi_btns_tcms_[i]->setChecked(i==0);
        btngroup_tcms_.addButton(navi_btns_tcms_[i],i*10);
    }
    connect(&btngroup_tcms_,SIGNAL(buttonClicked(int)),this,SIGNAL(signal_navibtn_index_tcms(int)));
}

void Navigation::InitCCTVNaviBtns()
{
    if(navinames_cctv_cn_.isEmpty())
        return;
    uint8_t btn_cnt = navinames_cctv_cn_.length();

    navi_btns_cctv_.append(ui->btn_cctv_1);
    navi_btns_cctv_.append(ui->btn_cctv_2);
    navi_btns_cctv_.append(ui->btn_cctv_3);

    for(int i=0;i<btn_cnt;i++)
    {
        navi_btns_cctv_[i]->setText(navinames_cctv_cn_.at(i));
        navi_btns_cctv_[i]->setCheckable(true);
        navi_btns_cctv_[i]->setChecked(i==0);
        btngroup_cctv_.addButton(navi_btns_cctv_[i],i*10);
    }
    connect(&btngroup_cctv_,SIGNAL(buttonClicked(int)),this,SIGNAL(signal_navibtn_index_cctv(int)));
}

void Navigation::setNaviBtnChecked(int id)
{
    QAbstractButton* btnChecked = btngroup_tcms_.checkedButton();
    btnChecked->setChecked(false);
    QAbstractButton* firstBtn = btngroup_tcms_.button(id);
    firstBtn->setChecked(true);
}
